<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else

    include 'livestock.html';
                
    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
    
    switch($_GET['action']) {
        case 'edit':
    
            switch ($_GET['type']) {
            //update fish
            case 'Fish':                

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Function to make a valid date input
            $date = $year."-".$month."-".$day;

            //SQL Query to add tank info
             $qry = "update livestock set category='".$_POST['category']."',name='".$_POST['name']."',type='".$_POST['type']."',supplier='".$_POST['supplier']."',purchase_date='$date',cost='".$_POST['cost']."' where lv_id ='".$_GET['lv_id']."' and user_id='".$_SESSION['uid'] ."'";

            break;
           
            //update corals
            case 'Coral':                

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Function to make a valid date input
            $date = $year."-".$month."-".$day;

            //SQL Query to add tank info
            $qry = "update livestock set category='".$_POST['category']."',name='".$_POST['name']."',type='".$_POST['type']."',supplier='".$_POST['supplier']."',purchase_date='$date',cost='".$_POST['cost']."' where lv_id ='".$_GET['lv_id']."' and user_id='".$_SESSION['uid'] ."'";

            break;
            
            //update inverts
            case 'invert':

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Function to make a valid date input
            $date = $year."-".$month."-".$day;

            //SQL Query to add tank info
             $qry = "update livestock set category='".$_POST['category']."',name='".$_POST['name']."',type='".$_POST['type']."',supplier='".$_POST['supplier']."',purchase_date='$date',cost='".$_POST['cost']."' where lv_id ='".$_GET['lv_id']."' and user_id='".$_SESSION['uid'] ."'";
            
            //update inverts
            case 'live':

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Function to make a valid date input
            $date = $year."-".$month."-".$day;

            //SQL Query to add tank info
            $qry = "update livestock set category='".$_POST['category']."',name='".$_POST['name']."',type='".$_POST['type']."',supplier='".$_POST['supplier']."',purchase_date='$date',cost='".$_POST['cost']."' where lv_id ='".$_GET['lv_id']."' and user_id='".$_SESSION['uid'] ."'";
            
            
           }
           
        break;
      }
        
        //Execute Insert command
        if (!mysql_query($qry,$con))
            {
              die('Error: ' . mysql_error());
            }
            echo "Livestock updated!"; 
            
               
    //Close SQL input
    mysql_close($con);

?>
